using System;
using Awaiter;
using YesPlayLove.Classes;
using YesPlayLove.Clusters;

namespace YoshiFlowMain
{
    //[IgnoreNamespace] Don't use because full class name is used in Master.cs to find this class
    public sealed class EmailPage : YoshiPage
    {
        private EmailCluster _emailCluster;

        public EmailPage()
        {
            new Await().AddAw(BasicBuildAw, EmailTheme.PageTitle).Commit();
        }

        public override void RefreshAw(Await awp)
        {
            new Await()
                .AddDx(
                    delegate
                    {
                        if (Script.IsValue(_emailCluster))
                            _emailCluster.Destroy();
                    }
                )
                .AddDx(delegate { _emailCluster = new EmailCluster(null); })
                .AddDx(delegate { _emailCluster.Build(true); })
                .AddDx(delegate { _emailCluster.Element.AppendTo(PageCluster); })
                .Commit(awp);
        }

        public override void Destroy()
        {
            if (_emailCluster != null)
                _emailCluster.Destroy();
        }

    }
}